<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我要进货</title>
    <link type="text/css" rel="stylesheet" href="./layui/css/layui.css"/>
</head>
<body class="layui-layout-body">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>我要进货</legend>
</fieldset>
<div class="layui-body" style="left: 13px;margin-top: 68px;">
    <!-- 内容主体区域 -->
    <script type="text/javascript" src="layui/layui.all.js"></script>
    <div style="padding: 20px;">批发货品</div>
    <form class="layui-form" action="">

        <div class="layui-form-item">
            <label class="layui-form-label">货品名称</label>
            <div class="layui-input-block">
                <input name="pname" lay-verify="title" autocomplete="off" placeholder="请输入货品名称" class="layui-input  title"
                       type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">货品进价</label>
            <div class="layui-input-block">
                <input name="pgetprice" lay-verify="title" autocomplete="off" placeholder="请输入货品进价" class="layui-input  title"
                       type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">货品售价</label>
            <div class="layui-input-block">
                <input name="psaleprice" lay-verify="title" autocomplete="off" placeholder="请输入货品售价" class="layui-input  title"
                       type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">到期时间</label>
            <div class="layui-input-block">
                <input name="pduetime" lay-verify="title" autocomplete="off" placeholder="请输入货品到期时间" class="layui-input  title"
                       type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">批发数量</label>
            <div class="layui-input-block">
                <input name="pcount" lay-verify="title" autocomplete="off" placeholder="请输入批发数量" class="layui-input  title"
                       type="text">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label state">是否上架</label>
            <div class="layui-input-block" style="padding-top: 13px">
                <input name="close" lay-skin="switch" lay-text="ON|OFF" type="checkbox" class="state">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="button" class="layui-btn submit" value="批发货品">
            </div>
        </div>
    </form>
</div>

<script src="./layui/layui.all.js"></script>
<script type="text/javascript" src="./jquery-1.9.1.js"></script>
<script>
    layui.use('layedit', function () {
        var layedit = layui.layedit
            , $ = layui.jquery;

        //构建一个默认的编辑器
        var index = layedit.build('LAY_demo1');

    });
    //    var $ = layui.jquery;
    $(".submit").click(function () {
        console.log(".....")
        var $pname = $("input[name='pname']").val();
        var $pgetprice = $("input[name='pgetprice']").val();
        var $psaleprice = $("input[name='psaleprice']").val();
        var $pduetime = $("input[name='pduetime']").val();
        var $pcount = $("input[name='pcount']").val();
        var $tag = $(".state").serialize();
        if ($tag === "") {
            $tag = 0;
        } else {
            $tag = 1;
        }

        var formdata = "pname=" + $pname + "&pgetprice=" + $pgetprice + "&psaleprice=" + $psaleprice + "&pduetime=" + $pduetime + "&pcount=" + $pcount + "&tag=" + $tag;
        console.log(formdata);
        $.ajax({
            url: "/onsale.action",
            type: "POST",
            data: formdata
        }).done(function (data) {
            console.log(data.msg)
            if (data.msg === "进货成功") {
                window.alert("进货成功");
            } else {
                window.alert("进货失败");
            }
        }).fail()
    });
</script>
</body>
</html>